package com.itheima.dao;

import com.itheima.domain.Orders;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IOrdersDao {
    /**
     * 查询所有订单
     * @return
     * @throws Exception
     */
    @Select("select * from orders")
    @Results({
            @Result(id=true,column = "id",property = "id"),@Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId",property = "product",one = @One(select = "com.itheima.dao.IProductDao.findProductById"))
    })
    public List<Orders> findAllOrders()throws Exception;

    /**
     * 根据订单编号查询订单信息
     * @param id
     * @return
     * @throws Exception
     */
    @Select("select * from orders where id = #{id} ")
    @Results({
            @Result(id=true,column = "id",property = "id"),
            @Result(column = "orderNum",property = "orderNum"),
            @Result(column = "orderTime",property = "orderTime"),
            @Result(column = "orderStatus",property = "orderStatus"),
            @Result(column = "peopleCount",property = "peopleCount"),
            @Result(column = "payType",property = "payType"),
            @Result(column = "orderDesc",property = "orderDesc"),
            @Result(column = "productId",property = "product",one = @One(select = "com.itheima.dao.IProductDao.findProductById")),
            @Result(column = "id",property = "travellers",javaType=List.class, many = @Many(select = "com.itheima.dao.ITravellerDao.findTravellerByOrderId")),
            @Result(column = "memberId",property = "member",one = @One(select = "com.itheima.dao.IMemberDao.findMemberById")),
    })
    public Orders findOrdersById(String id)throws Exception;
}
